<template>
  <div class="app-container">
    <el-form :inline="true" :model="queryParams" class="demo-form-inline">
      <el-form-item label="卡片名称">
        <el-input v-model="queryParams.name" placeholder="请输入卡片名称" />
      </el-form-item>

      <el-form-item label="卡片编号">
        <el-input v-model="queryParams.number" placeholder="请输入卡片编号" />
      </el-form-item>
      <!-- 卡包id -->
      <el-form-item label="卡包id">
        <el-input v-model="queryParams.cardBoxId" placeholder="请输入卡包id" />
      </el-form-item>


      <el-form-item>
        <div style="display: flex; gap: 10px;">
          <el-button type="primary" @click="getTujianCardList">查询</el-button>
          <el-button type="reset" @click="resetQuery">重置</el-button>
        </div>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="tujianCardList" border height="73vh">
      <el-table-column label="卡片图片" align="center" width="100">
        <template slot-scope="scope">
          <el-image style="width: 100px; height: 100px" :src="scope.row.imageUrl || scope.row.image" fit="contain"
            :preview-src-list="[scope.row.imageUrl || scope.row.image]" />
        </template>
      </el-table-column>
      <el-table-column label="卡片ID" align="center" prop="id" />

      <!-- 卡盒ID -->
      <el-table-column label="卡包id" align="center" prop="cardBoxId" />


      <el-table-column label="显示名称" align="center" prop="displayName" />
      <el-table-column label="原始名称" align="center" prop="name" />
      <el-table-column label="卡片编号" align="center" prop="number" />
      <el-table-column label="稀有度" align="center" prop="rare" />
      <el-table-column label="发行年份" align="center" prop="year" />

      <el-table-column label="市场价格" align="center" prop="price" />
      <el-table-column label="卡牌类型" align="center" prop="cardTypeDisplayName" />
      <el-table-column label="卡牌语言" align="center" prop="cardTypeLanguage" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog :title="'编辑卡片'" :visible.sync="editDialogVisible" width="500px" append-to-body>
      <el-form ref="editForm" :model="editForm" :rules="rules" label-width="80px">

        <!-- displayName -->
        <el-form-item label="显示名称" prop="displayName">
          <el-input v-model="editForm.displayName" placeholder="请输入显示名称" />
        </el-form-item>
        <el-form-item label="卡片名称" prop="name">
          <el-input v-model="editForm.name" placeholder="请输入卡片名称" />
        </el-form-item>
        <el-form-item label="卡片编号" prop="number">
          <el-input v-model="editForm.number" placeholder="请输入卡片编号" />
        </el-form-item>
        <el-form-item label="稀有度" prop="rare">
          <el-input v-model="editForm.rare" placeholder="请输入稀有度" />
        </el-form-item>
        <el-form-item label="发行年份" prop="year">
          <el-input v-model="editForm.year" placeholder="请输入发行年份" />
        </el-form-item>
        <el-form-item label="市场价格" prop="price">
          <el-input v-model="editForm.price" placeholder="请输入市场价格" />
        </el-form-item>
        <!-- cardTypeDisplayName -->
        <el-form-item label="卡牌类型" prop="cardTypeDisplayName">
          <el-input v-model="editForm.cardTypeDisplayName" placeholder="请输入卡牌类型" />
        </el-form-item>
        <!-- cardTypeLanguage -->
        <el-form-item label="卡牌语言" prop="cardTypeLanguage">
          <el-input v-model="editForm.cardTypeLanguage" placeholder="请输入卡牌语言" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="editDialogVisible = false">取 消</el-button>
      </div>
    </el-dialog>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getTujianCardList" />
  </div>
</template>
<script>
import { getTujianCardList } from '@/api/system/cardMange';
import { importFolderAddData } from '@/api/system/tujian';
export default {
  data() {
    return {
      loading: false,
      tujianCardList: [],
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      editDialogVisible: false,
      editForm: {},
      rules: {
        name: [{ required: true, message: '请输入卡片名称', trigger: 'blur' }],
        number: [{ required: true, message: '请输入卡片编号', trigger: 'blur' }],
        rare: [{ required: true, message: '请输入稀有度', trigger: 'blur' }],
        year: [{ required: true, message: '请输入发行年份', trigger: 'blur' }],
        price: [{ required: false, message: '请输入市场价格', trigger: 'blur' }]
      },
    }
  },
  created() {
    this.getTujianCardList();
  },
  methods: {
    getTujianCardList() {
      this.loading = true;
      getTujianCardList(this.queryParams).then(res => {
        this.tujianCardList = res.data.records;
        this.total = res.data.total;
      }).finally(() => {
        this.loading = false;
      })
    },
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        name: '',
        number: '',
      };
      this.getTujianCardList();
    },
    handleUpdate(row) {
      this.editForm = Object.assign({}, row);
      this.editDialogVisible = true;
    },
    submitForm() {
      this.$refs.editForm.validate(valid => {
        if (valid) {
          importFolderAddData(this.editForm).then(res => {
            this.$modal.msgSuccess('修改成功');
            this.editDialogVisible = false;
            this.getTujianCardList();
          });
        }
      });
    },
  }

};
</script>
<style scoped lang="scss"></style>
